import React, { useState } from 'react';
import { Form, Input, Upload, Button, Select, Switch, Avatar, Space, message, Radio, TreeSelect } from 'antd';
import { LockOutlined  } from '@ant-design/icons';
import { userStore } from '../store/userStore';
import { Pwd } from '../store/userTypes';

const { Option } = Select;

interface PasswordFormProps {
  type: 'create';
  initialValues?: any;
  onCancel: () => void;
}

const PasswordForm: React.FC<PasswordFormProps> = ({ type,  onCancel }) => {
  const [form] = Form.useForm();

  const onFinish = (values: Pwd) => {
    userStore.batchUpdatePwd(values);
    onCancel();
  };

  return (
    <Form
      form={form}
      layout="vertical"
      onFinish={onFinish}
    >
      <Form.Item
        label="用户"
        name={'ids'}
        rules={[{ required: true, message: '请选择用户' }]}
      >
        <TreeSelect
          treeData={userStore.userOptions}
          placeholder="请选择用户"
          treeCheckable
          showCheckedStrategy="SHOW_PARENT"
          style={{ width: '100%' }}
        />
      </Form.Item>

      <Form.Item
        label="密码"
        name="password"
        rules={[
          { required: true, message: '请输入新密码！' },
          { min: 8, message: '密码长度不能少于8位！' }
        ]}
      >
        <Input.Password prefix={<LockOutlined />} placeholder="请输入新密码" />
      </Form.Item>
      <Form.Item>
        <Space>
          <Button type="primary" htmlType="submit">
            保存
          </Button>
          <Button onClick={onCancel}>取消</Button>
        </Space>
      </Form.Item>
    </Form>
  );
};

export default PasswordForm; 